package org.lql.algo.codecrush.week007;

/**
 * @author: liangqinglong
 * @date: 2025-08-18 13:38
 * @description: 852. 山脉数组的峰顶索引 <a href="https://leetcode.cn/problems/peak-index-in-a-mountain-array/description/">...</a>
 **/
public class PeakIndexInMountainArray {

	public int peakIndexInMountainArray(int[] arr) {
		int left = 0;
		int right = arr.length - 1;
		while (left < right) {
			int mid = left + (right - left) / 2;
			if (arr[mid] < arr[mid + 1]) {
				left = mid + 1;
			} else {
				right = mid;
			}
		}
		return right;
	}

	public static void main(String[] args) {
		int[] arr = {0, 1, 0};
		PeakIndexInMountainArray peakIndexInMountainArray = new PeakIndexInMountainArray();
		System.out.println(peakIndexInMountainArray.peakIndexInMountainArray(arr));
		arr = new int[]{0, 2, 1, 0};
		System.out.println(peakIndexInMountainArray.peakIndexInMountainArray(arr));
		arr = new int[]{0, 10, 5, 2};
		System.out.println(peakIndexInMountainArray.peakIndexInMountainArray(arr));
	}
}
